package com.xdf.xzymanagementsystem.util;

import com.xdf.xzymanagementsystem.entity.Computer;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.Optional;

@Component
public class HardwareUtils {

    // 获取本机计算机名、用户名、计算机所在域
    @Bean
    public Computer serverComputer(){
        Map<String, String> map = System.getenv();
        String userName = map.get("USERNAME");// 获取用户名
        String computerName = map.get("COMPUTERNAME");// 获取计算机名
        String userDomain = map.get("USERDOMAIN");// 获取计算机域名

        Computer computer = new Computer();
        computer.setComputerName(Optional.ofNullable(computerName).orElse(""));
        computer.setUserName(Optional.ofNullable(userName).orElse(""));
        computer.setUserDomain(Optional.ofNullable(userDomain).orElse(""));

        return computer;
    }
}
